package guiBeatporty;

import java.awt.EventQueue;

import javax.swing.JInternalFrame;
import javax.swing.UIManager;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JPasswordField;
import javax.swing.JCheckBox;
import javax.swing.JButton;

import Controle.Controlador;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import javax.swing.border.LineBorder;
import java.awt.Color;
import java.io.IOException;

public class CadastroUsuario extends JInternalFrame {
	private JTextField txtNome;
	private JTextField txtEndereco;
	private JTextField txtCidadeEstado;
	private JTextField txtLogin;
	private JPasswordField passwordField;
	
	private JCheckBox ckbxHouse;
	
	private JCheckBox ckbxTechno;
	
	private JCheckBox ckbxReggae;
	
	private JCheckBox ckbxHiphop;
	
	private JCheckBox ckbxRock;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					CadastroUsuario frame = new CadastroUsuario();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public CadastroUsuario() {
		setBorder(new LineBorder(new Color(0, 0, 0)));
		setBounds(100, 100, 538, 328);
		
		JLabel lblNome = new JLabel("Nome:");
		
		txtNome = new JTextField();
		txtNome.setColumns(10);
		
		JLabel lblEndereo = new JLabel("Endere\u00E7o:");
		
		txtEndereco = new JTextField();
		txtEndereco.setColumns(10);
		
		JLabel lblCidadeestado = new JLabel("Cidade/Estado:");
		
		txtCidadeEstado = new JTextField();
		txtCidadeEstado.setColumns(10);
		
		JLabel lblLogin = new JLabel("Login:");
		
		txtLogin = new JTextField();
		txtLogin.setColumns(10);
		
		JLabel lblSenha = new JLabel("Senha:");
		
		passwordField = new JPasswordField();
		
		JLabel lblEstilosPreferidos = new JLabel("Estilos Preferidos:");
		
		ckbxHouse = new JCheckBox("House");
		
		ckbxTechno = new JCheckBox("Techno");
		
		ckbxReggae = new JCheckBox("Reggae");
		
		ckbxHiphop = new JCheckBox("HipHop");
		
		ckbxRock = new JCheckBox("Rock");
		
		JButton btnOk = new JButton("Ok");
		btnOk.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String nome = txtNome.getText();
				String end = txtEndereco.getText();
				String CidadeEstado = txtCidadeEstado.getText();
				String login = txtLogin.getText();
				String senha = passwordField.getText();
				
				ArrayList<Integer> estilos = new ArrayList(5);
				if(ckbxHouse.isSelected())
					estilos.add(Controlador.getControlador().HOUSE);
				if(ckbxTechno.isSelected())
					estilos.add(Controlador.getControlador().TECHNO);
				if(ckbxReggae.isSelected())
					estilos.add(Controlador.getControlador().REGGAE);
				if(ckbxHiphop.isSelected())
					estilos.add(Controlador.getControlador().HIP_HOP);
				if(ckbxRock.isSelected())
					estilos.add(Controlador.getControlador().ROCK);
				
				Controlador.getControlador().novoUsuario(nome, end, CidadeEstado, login, senha, estilos);
				Controlador.getControlador().login(login, senha);
				Controlador.getControlador().setMainFrameUserInfo();
				try {
					Controlador.getControlador().salvarDados();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				MainFrame.resizeMainFrame(true);
				dispose();
			}
		});
		GroupLayout groupLayout = new GroupLayout(getContentPane());
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addGroup(groupLayout.createSequentialGroup()
							.addContainerGap()
							.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
								.addComponent(lblEndereo)
								.addComponent(lblNome)
								.addComponent(lblLogin)
								.addComponent(lblSenha)
								.addComponent(lblCidadeestado))
							.addPreferredGap(ComponentPlacement.RELATED)
							.addGroup(groupLayout.createParallelGroup(Alignment.LEADING, false)
								.addComponent(txtCidadeEstado)
								.addComponent(passwordField)
								.addComponent(txtLogin)
								.addComponent(txtNome)
								.addComponent(txtEndereco, GroupLayout.DEFAULT_SIZE, 243, Short.MAX_VALUE))
							.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
								.addGroup(groupLayout.createSequentialGroup()
									.addGap(52)
									.addComponent(lblEstilosPreferidos))
								.addGroup(groupLayout.createSequentialGroup()
									.addGap(70)
									.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
										.addComponent(ckbxHiphop)
										.addComponent(ckbxRock)
										.addComponent(ckbxTechno)
										.addComponent(ckbxReggae)
										.addComponent(ckbxHouse)))))
						.addGroup(groupLayout.createSequentialGroup()
							.addGap(221)
							.addComponent(btnOk, GroupLayout.PREFERRED_SIZE, 79, GroupLayout.PREFERRED_SIZE)))
					.addContainerGap(69, Short.MAX_VALUE))
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGap(28)
					.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblNome)
						.addComponent(txtNome, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(lblEstilosPreferidos))
					.addGap(18)
					.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblEndereo)
						.addComponent(txtEndereco, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(ckbxHouse))
					.addPreferredGap(ComponentPlacement.RELATED)
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addGroup(groupLayout.createSequentialGroup()
							.addGap(13)
							.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
								.addComponent(txtCidadeEstado, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
								.addComponent(lblCidadeestado))
							.addGap(27)
							.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
								.addComponent(lblLogin)
								.addComponent(txtLogin, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
							.addPreferredGap(ComponentPlacement.UNRELATED)
							.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
								.addComponent(lblSenha)
								.addComponent(passwordField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
						.addGroup(groupLayout.createSequentialGroup()
							.addGap(3)
							.addComponent(ckbxTechno)
							.addPreferredGap(ComponentPlacement.UNRELATED)
							.addComponent(ckbxReggae)
							.addPreferredGap(ComponentPlacement.UNRELATED)
							.addComponent(ckbxHiphop)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(ckbxRock)))
					.addGap(32)
					.addComponent(btnOk)
					.addContainerGap(47, Short.MAX_VALUE))
		);
		getContentPane().setLayout(groupLayout);

	}
}
